<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>09-嵌套路由demo</title>
</head>
<body>
  <div id="app">
    <h1>Hello VueRouter!</h1>
    <p>
      <router-link to='/user/bar/profile'>用户profile</router-link>
      <router-link to='/user/foo/posts'>用户posts</router-link>
    </p>
    <router-view></router-view>
  </div>
</body>
<!-- 引入vue -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 引入VueRouter -->
<script src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script>
  const UserProfile = {
    template:`<div>用户偏好设置</div>`
  }
  const UserPosts = {
    template:`<div>用户posts</div>`
  }
  const User = {
    template:`<div>
        <h1>这里是User组件 {{$route.params.id}}</h1>
        <router-view></router-view>
      </div>`
  }
  var routes = [
    {path:'',component:User,name:'xxx'},
    {path:'/user/:id',component:User,children:[
      {path:'profile',component:UserProfile},
      {path:'posts',component:UserPosts},
    ]}
  ]
  var router = new VueRouter({
    routes
  })
  var app = new Vue({
    el:'#app',
    router
  })
</script>
</html>